<html>
<head>
<style>
body>div {
  margin: 20px 35px;
  float:left;
}
</style>
<script type="text/javascript" src="lib/jquery.min.js"></script>    
<script type="text/javascript" src="lib/jquery-barcode-last.js"></script>   
<style>
@media print {
  table {
    page-break-after:always;
  }
}

table {
  width:100%;  
}

.cnt {
  width:30px;    
}

.name {
  width:200px;    
}

h1 {  
	text-align: center;  
}

body {
  margin: 0;
  font-family: Helvetica, Arial, FreeSans, sans-serif;
  font-size: 14px;
  height: 100%;
}

</style>
<script language='javascript'>
function run(){
  
<?php>

ini_set('display_errors', 'On');
error_reporting(E_ALL);

  require_once('functions.php');
  
  
  $db = getConnection();
  
 
  $result = $db->query("select * from groep where id != 0");
 
  foreach($result as $row) {
    echo "$(\"#b".$row['barcode']."\").barcode(\"".$row['barcode']."\", \"code128\", {barWidth:2, barHeight:25});";
  }
?>
}
</script>
</head>
<body onload="run();">

<?php
 
  $result = $db->query(
    "SELECT p.roepnaam as roepnaam, p.tussenvoegsel as tussenvoegsel, p.achternaam as achternaam, ".
    "p.bijzonderheden as bijzonderheden, p.polsband as polsband, g.kleur as kleur, g.barcode as barcode, g.opmerking as opmerking " .
    "FROM persoon as p " . 
    "join groep as g on p.groepId = g.id " .
    "order by p.groepId, p.roepnaam");

  $kleur = "";
  $cnt = 1;
  echo "<table>";
  foreach($result as $row) {
    if ($kleur != $row['kleur']) {
      echo "</table>";
      echo "<h1>" . $row['kleur'] . "";
    
    
     echo "<div style=\"float: right;\" id='b".$row['barcode']."'>".$row['barcode']."</div></h1>";
     
      echo "<p>" . $row['opmerking'] . "</p>";
      echo "<table><tr><th class='cnt'></th><th class='name'>Deelnemers</th><th class='bz'>Bijzonderheden</th></tr>";
      $kleur = $row['kleur'];
      $cnt = 1;
    }
    
    echo "<tr><td>" . $cnt++ . "<td><td>" . $row['polsband'] . ". </td><td>".$row['roepnaam'] . " " . $row['tussenvoegsel'] . " " . $row['achternaam'] . " </td><td>" . $row['bijzonderheden'] . " </td></tr>";
    
  } 
  echo "</table>";
  closeConnection($db);
?>



</body>
</html>
